<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
namespace Album\Form;
use Zend\Form\Form;

use Zend\Db\Adapter\AdapterInterface;
class AlbumForm extends Form  {
    protected  $albumTable;
    protected $dbAdapter;
    public function __construct(AdapterInterface $dbAdapter) {
        
        $this->setDbAdapter($dbAdapter);
        parent::__construct('album');       
        $this->add(array(
            'name' =>'id',
            'type' =>'hidden',
        ));
        $this->add(array(
            'name' =>'title',
            'type' => 'text',
            'options' =>array(
               'label'=>'Title',
            ),
        ));
        $this->add(array(
            'name' => 'artist',
            'type' => 'text',
            'options' => array(
                'label' => 'Artist',
            ),
        ));
        /*$this->add(array(
            'name'    => 'db-select',
            'type'    => 'Zend\Form\Element\Select',
            'options' => array(
                'label'         => 'Dynamic DbAdapter Select',
                'value_options' => $this->getOptionsForSelect(),
                'empty_option'  => '--- please choose ---'
            )
        ));
        */
        $this->add(array(
            'name' => 'submit',
            'type' => 'submit',
            'attributes' => array(
                'value' => 'Go',
                'id'    => 'submitbutton'
            ),
        ));
        
    }
    public function getOptionsForSelect(){
       $dbAdapter = $this->getDbAdapter();
        $sql       = 'SELECT t0.id, t0.title FROM selectoptions t0 ORDER BY t0.title ASC';
        $statement = $dbAdapter->query($sql);
        $result    = $statement->execute();

        $selectData = array();

        foreach ($result as $res) {
            $selectData[$res['id']] = $res['title'];
        }

        return $selectData;
    }
    public function setDbAdapter(AdapterInterface $dbAdapter)
    {
        $this->dbAdapter = $dbAdapter;

        return $this;
    }

    public function getDbAdapter()
    {
        return $this->dbAdapter;
    }

    public function getDriver() {
        
    }

    public function getPlatform() {
        
    }
    

}